const electron = require('electron')

var menu = Require('./component/_menu.js')(); // 载入菜单 
var list = Require('./component/_list.js').list(); // 载入列表
var search = Require('./component/_search.js')(); // 载入搜索列表

var moveBer = Require('./component/_moveBer.js')({
    type: 'x',
    position: '250'
}); // 载入移动组件
var tab = Require('./component/_tab.js')(); // 载入选项卡 
var content = Require('./component/_content.js')(); // 载入内容
var shallMenu = Require('./component/_shallMenu.js')(); // 右键菜单 
var chooseFolder = Require('./component/_chooseFolder.js').chooseFolder; //文件夹选择器
var statusBar = Require('./component/_statusBar.js')(); //状态栏
var dialogEX = Require('./component/_dialog.js'); //弹出框
var note = Require('./component/_note.js')(); //记事本
var modal = Require('./component/_modal.js').modal();
var urlModal = Require('./component/_url.js')();

var Export = Require('./component/export.js');

$('body').append(menu.render());
$('body').append(list.render());
$('body').append(moveBer.render());
$('body').append(tab.render());
$('body').append(content.render());
$('body').append(search.render());
$('body').append(statusBar.render());
$('body').append(note.render());
$('body').append(modal.render());
$('body').append(urlModal.render());


menu.addButton([{
    key: 'list',
    title: '列表',
    icon: "fa-th-list",
    active: true,
    showEvent: function () {
        list.show();
    },
    hideEvent: function () {
        list.hide();
    }
}, {
    key: 'search',
    title: '搜索',
    icon: "fa-search",
    active: false,
    showEvent: function () {
        search.show();
    },
    hideEvent: function () {
        search.hide();
    }
}, {
    key: 'note',
    title: '记事本',
    icon: "fa-file-text",
    active: false,
    showEvent: function () {
        note.show();
    },
    hideEvent: function () {
        note.hide();
    }
}, {
    key: 'modal',
    title: '模型',
    icon: "fa-puzzle-piece",
    active: false,
    showEvent: function () {
        modal.show();
    },
    hideEvent: function () {
        modal.hide();
    }
}, {
    key: 'urlModal',
    title: 'URL',
    icon: "fa-gears",
    active: false,
    showEvent: function () {
        urlModal.show();
    },
    hideEvent: function () {
        urlModal.hide();
    }
}]);


// 绑定moveBar
moveBer.on('check', function (num) {
    if (num < 220) {
        num = 220;
    } else if (num > 450) {
        num = 450
    };
    return num;
});
// 计算拖动栏执行后的移动事件
moveBer.on('move', function (num) {
    list.setWidth(num - 50 - 2);
    search.setWidth(num - 50 - 2);
    tab.setLeft(num - 2);
    content.setLeft(num - 2);
});

var saveUserLastConttol = function () {
    var listCache = list.getCache();
    var tabCacge = tab.getCache();
    var cacheData = {
        "tabArray": tabCacge.tabArray,
        "tabActiveObjId": tabCacge.tabActiveObjId,
        "listArray": listCache.listArray,
        "listActiveObjId": listCache.listActiveObjId,
        "time": new Date().getTime(),
        "cache": JSON.stringify(__CacheValue__),
        "urlSetting": content.urlSelect.valueData.url,
    };
    proxy.setPorjectLastControl(__DBConfig__.id, cacheData, function () {
        statusBar.set(cacheData.time);
    });
};


// 列表刷新事件
list.on('refresh', function (event, callback) {
    if (list.root) {
        list.root.clear();
    };
    // 人为制造一个刷新感官
    $('body').loadingEX();
    setTimeout(() => {
        __DBObject__.list.getAll(function (error, data) {
            $('body').loadingEX();
            event.setData(data);
            if (callback) {
                callback();
                saveUserLastConttol();
            };
        });
    }, 100);
});

// 列表选中事件 
// 如果为接口,则在TAB中打开一项
list.on('active', function (event) {
    doSaveEvent();
    search.active(event.config.id);
    tab.open(event.config);
});

// 绑定右键菜单
list.on('shallMenu', function (a, b, c) {
    shallMenu.render(a, b, c);
});

list.on('export', function () {
    Export();
});


// TAB 的焦点事件
tab.onActive(function (event, formInSide) {
    search.active(event.oldData.id);
    doSaveEvent();
    // 如果从内部触发，则在列表中选中对应项
    if (formInSide) {
        list.active(event.oldData.id);
    };
    // 渲染 CONTENT
    content.set(event.newData);
    // 隐藏遮罩层
    content.hideMark();
    // 如果TAB中接口已经响应，输出响应结果
    event.response();
});

// 当TAB列表为空时
tab.onEmpty(function () {
    // 显示遮罩层
    content.showMark();
    // 让list列表取消选中
    list.unActive();
});

var _chooseFolderDialog = null;
var _saveDialog = null;

// tab 的保存事件
tab.onSave(function (event, cb) {
    // 如果为新接口 （在LIST中不存在）
    if (event.isNew) {
        // 使选择文件夹对话框只能存在一个
        if (!_chooseFolderDialog) {
            // 生成选择文件夹对话框
            _chooseFolderDialog = new chooseFolder();
            // 选择文件夹对话框的确定事件
            _chooseFolderDialog.event.chooseEnd = function (dialogevent, activeData, chooseData) {
                event.newData.parentId = activeData.id;
                // 创建接口
                $('body').loadingEX();
                __DBObject__.list.creat(event.newData, function (error, data) {
                    $('body').loadingEX();
                    if (error) {
                        dialogEX({
                            title: '警告',
                            body: '<div style="padding:20px;">' + error + '</div>',
                            buttons: [{
                                text: '确定',
                                event: (event) => {
                                    event.close();
                                },
                            }],
                            width: 400,
                            height: 200,
                        });
                    } else {
                        // 关闭对话框
                        // 刷新列表
                        list.refresh(function () {
                            // 将保存好的对象重新传递给TAB进行操作,以便刷新TAB
                            cb(data);
                            dialogevent.close();
                            _chooseFolderDialog = null;
                        });
                        // 删除对话框对象
                    }
                });
            };
            // 调用选择文件夹对话框的展开事件
            _chooseFolderDialog.render(list.__FolderArray, function () {
                _chooseFolderDialog = null;
            });
        };
    } else {
        // 如果不是新接口(list中已经存在)
        // 直接保存
        if (!_saveDialog) {
            _saveDialog = dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">是否替换服务器上的数据?</div>',
                buttons: [{
                    text: '是',
                    event: (dialogEvent) => {
                        $('body').loadingEX();
                        __DBObject__.list.upData(event.oldData.id, event.newData, function (error, data) {
                            $('body').loadingEX();
                            if (error) {
                                dialogEX({
                                    title: '警告',
                                    body: '<div style="padding:20px;">' + error + '</div>',
                                    buttons: [{
                                        text: '确定',
                                        event: (event) => {
                                            event.close();
                                        },
                                    }],
                                    width: 400,
                                    height: 200,
                                });
                            } else {
                                // 刷新类表,同上
                                list.refresh(function () {
                                    cb(event.newData);
                                    dialogEvent.close();
                                    _saveDialog = null;
                                });
                            }
                        });
                    },
                }, {
                    text: '否',
                    event: (dialogEvent) => {
                        dialogEvent.close();
                        _saveDialog = null;
                    },
                }],
                width: 400,
                height: 200,
                closeEvent: function () {
                    _saveDialog = null;
                }
            });
        };
    };
    // list.refresh();
    // list.active(event.oldData.id);
});

tab.on('shallMenu', function (a, b, c) {
    shallMenu.render(a, b, c);
});

// content对象的任意值改变时
// 用于触发tab中的是否修改命令
content.onChange(function (type, data, id) {
    // tab中会验证与打开TAB是的数据是否一致,
    // 从而验证是否需要保存
    tab.change(type, data, id);
});

// content对象中的发送按钮事件
content.onSend(function (id, url) {
    // 需要tab子对象中的send的返回值,判断是否发送成功
    return tab.items[id].send(url);
});

// content对象中取消请求按钮事件
content.onCancel(function (id) {
    tab.items[id].cancel();
});


// content对象中的保存命令
content.onSave(function (id) {
    // 直接调用tab中的保存命令
    tab.save(id);
});


content.on('getModal', function (cb) {
    $('body').loadingEX();
    __DBObject__.Modal.getAll(function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Get All Modal ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});
content.on('getUrl', function (cb) {
    $('body').loadingEX();
    __DBObject__.Url.getAll(function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Get All URL : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});


content.on('getOldDate', function (id, cb) {
    if (list.items.hasOwnProperty(id) && tab.items.hasOwnProperty(id)) {
        cb(tab.items[id].oldData);
    }
});


// tab中接口调用的响应结果
tab.onResponse(function (status, body, id) {
    content.setSendStatus(status, body, id);
});

tab.onAdd(function () {
    doSaveEvent();
    list.unActive();
});

// list 右键菜单的重命名事件绑定
// 只有文件夹有重命名事件
shallMenu.on('rename', function (obj) {
    obj.rename();
});

window.ReName = function () {
    if (list.activeObj.isFolder) {
        list.activeObj.rename();
    };
};

// 右键菜单的删除命令
shallMenu.on('delete', function (obj) {
    obj.delete();
});
shallMenu.on('newFolder', function (obj) {
    obj.newFolder();
});

// 右键菜单的移动文件夹命令
shallMenu.on('move', function (obj) {
    obj.move();
});

var Guid = function () {
    var guid = '';
    for (var i = 1; i <= 32; i++) {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            guid += '-';
    }
    return guid;
};

// 右键菜单的另存为命令
shallMenu.on('other', function (obj) {
    doSaveEvent();
    // search.active(obj.config.id);
    var id = Guid();

    tab.open({
        id: id,
        title: obj.config.title,
        requestURL: obj.config.requestURL,
        header: obj.config.header,
        requestData: obj.config.requestData,
        contentType: obj.config.contentType,
        contentIndex: obj.config.contentIndex,
        description: obj.config.description,
    }, true, true, {
            id: id,
            title: obj.config.title,
            requestURL: obj.config.requestURL,
            header: obj.config.header,
            requestData: obj.config.requestData,
            contentType: obj.config.contentType,
            contentIndex: obj.config.contentIndex,
            description: obj.config.description,
        });
});

shallMenu.on('closeOther', function (obj) {
    tab.closeOther(obj);
});



// 列表子对象的重命名事件(只有文件夹可以重命名)
list.on('rename', function (data, newData) {
    data.contentIndex = newData.contentIndex;
    data.title = newData.title;
    $('body').loadingEX();
    __DBObject__.list.upData(data.id, data, function (error, data) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            list.refresh();
        }
    });
});

// 新建文件夹命令
list.on('newFolder', function (data, newData) {
    data.contentIndex = newData.contentIndex;
    data.title = newData.title;
    $('body').loadingEX();
    __DBObject__.list.creat(data, function (error, data) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            list.refresh(function () {
                // 由于列表缓存时,没有新文件夹的ID,
                // 所以需要手动将新建的文件夹设置为焦点
                list.active(data.id);
            });
        }
    });
});

// 删除列表中一项的命令
list.on('delete', function (data) {
    dialogEX({
        title: '警告',
        body: '<div style="padding:20px;">是否删除' + (data.contentType != 'folder' ? ' 接口 ：' : ' 文件夹 ：') + data.title + '？</div>',
        buttons: [{
            text: '确定',
            event: (event) => {
                tab.each(function (item) {
                    if (item.oldData.parentId == data.id) {
                        var _data_ = item.oldData;
                        _data_.parentId = data.parentId;
                        item.changeOldData();
                    };
                });
                $('body').loadingEX();
                __DBObject__.list.delete(data.id, function (error, _data) {
                    $('body').loadingEX();
                    if (error) {
                        dialogEX({
                            title: '警告',
                            body: '<div style="padding:20px;">' + error + '</div>',
                            buttons: [{
                                text: '确定',
                                event: (event) => {
                                    event.close();
                                },
                            }],
                            width: 400,
                            height: 200,
                        });
                    } else {
                        list.refresh(function () {
                            // 如果删除的对象类型为接口,
                            // 则需要关闭已经打开的TAB
                            if (data.contentType != 'folder') {
                                tab.close(data.id);
                            };
                        });
                    }
                });
                event.close();
            },
        }, {
            text: '取消',
            event: (event) => {
                event.close();
            },
        }],
        width: 400,
        height: 200,
    });
});

// 移动事件
list.on('move', function (activeData, listArray) {
    var _chooseFolderDialog = new chooseFolder(activeData);
    _chooseFolderDialog.event.chooseEnd = function (event, activeData, chooseData) {
        chooseData.parentId = activeData.id;
        $('body').loadingEX();
        __DBObject__.list.upData(chooseData.id, chooseData, function (error, data) {
            $('body').loadingEX();
            if (error) {
                dialogEX({
                    title: '警告',
                    body: '<div style="padding:20px;">' + error + '</div>',
                    buttons: [{
                        text: '确定',
                        event: (event) => {
                            event.close();
                        },
                    }],
                    width: 400,
                    height: 200,
                });
            } else {
                list.refresh(function () {
                    // 因为TAB中的事件行为已经被保存,
                    // 需要手动刷新TAB中的值
                    tab.items[chooseData.id].changeOldData(chooseData);
                });
                event.close();
            }
        });
    };
    _chooseFolderDialog.render(listArray);
});

search.on('renderList', function (event, data, contentType) {
    event.loading();
    __DBObject__.list.search(data, contentType, function (error, docs) {
        event.setData(docs);
        if (docs.length == 0) {
            event.showMark();
        };
        event.loading();
    });
});

search.on('active', function (data) {
    list.active(data.id);
});



window.list = list;

statusBar.onClick(saveUserLastConttol);

$('#readMessage').text('读取数据库......');
// 刷新类表事件
list.refresh(function () {
    tab.setCache(list.items, {
        "tabArray": __CacheData__.tabArray,
        "tabActiveObjId": __CacheData__.tabActiveObjId,
    });
    list.setCache({
        "listArray": __CacheData__.listArray,
        "listActiveObjId": __CacheData__.listActiveObjId,
    });
    statusBar.set(__CacheData__.time);

    if (__CacheData__.cache) {
        __CacheValue__ = JSON.parse(__CacheData__.cache)
    };

    setTimeout(() => {
        $('#pageLoad').css('opacity', '0');
        setTimeout(function () {
            $('#pageLoad').remove();
        }, 500);
    }, 1000);
});

// 5分钟保存一次用户操作记录
setTimeout(function () {
    saveUserLastConttol();
}, 1000 * 60 * 5);


// 当全局快捷键被触发是  Ctrl + S
// 直接触发保存命令

var doSaveEvent = function () {
    if (content.status) {
        content.titleInputObj.element.blur();
        content.descriptionTextareaObj.element.blur();
        content.textarea.blur();
        content.contentIndex.blur();
    };
}
// 保存事件
window.SaveEvent = function () {
    doSaveEvent();
    content.save();
};

// 渲染记事本
note.on('refresh', function (event, callback) {
    $('body').loadingEX();
    __DBObject__.Content.getAll(null, (error, docs) => {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">refresh : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            callback(docs);
        }
    });
});

note.on('getSubItems', function (id, cb) {
    $('body').loadingEX();
    __DBObject__.Content.getAll(id, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">getSubItems : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});

note.on('getImages', function (id, callback) {
    $('body').loadingEX();
    __DBObject__.Image.get(id, (error, docs) => {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">getImages : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            callback(docs);
        }
    });
});

note.on('getInterface', function (data, callback) {
    $('body').loadingEX();
    __DBObject__.list.GetByArray(data, (error, docs) => {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">getInterface : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            callback(docs);
        }
    });
});

note.on('jumpInterface', function (id) {
    menu.buttons.list.active();
    list.active(id, true);
});

note.on('creat', function (data, cb) {
    $('body').loadingEX();
    __DBObject__.Content.creat(data, (error, doc) => {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">creat : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(doc);
        }
    });
});

note.on('upDateImage', function (list, cb) {
    $('body').loadingEX();
    __DBObject__.Image.creatByArray(list, function (error, doc) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">upDateImage : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(doc);
        }
    });
});

note.on('deleteImage', function (list, cb) {
    $('body').loadingEX();
    __DBObject__.Image.deleteByArray(list, function (error, doc) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">deleteImage : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(doc);
        }
    });
});
note.on('searchInterface', function (data, contentType, cb) {
    $('body').loadingEX();
    __DBObject__.list.search(data, contentType, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">searchInterface : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});
note.on('updata', function (id, data, cb) {
    $('body').loadingEX();
    __DBObject__.Content.upDate(id, data, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">updata : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});
note.on('delete', function (id, cb) {
    $('body').loadingEX();
    __DBObject__.Content.delete(id, function (error, docs) {
        $('body').loadingEX();
        if (error) {

            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">delete : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});

note.refresh();



modal.on('get', function (cb) {
    $('body').loadingEX();
    __DBObject__.Modal.getAll(function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Get All Modal : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});


modal.on('creat', function (data, cb) {
    $('body').loadingEX();
    __DBObject__.Modal.creat(data, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Creat Modal : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});

modal.on('updata', function (id, data, cb) {
    $('body').loadingEX();
    __DBObject__.Modal.updata(id, data, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">UpData Modal : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});

modal.on('delete', function (id, cb) {
    $('body').loadingEX();
    __DBObject__.Modal.delete(id, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Delete Modal : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});


urlModal.on('getAll', function (cb) {
    $('body').loadingEX();
    __DBObject__.Url.getAll(function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Get All URL : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
        };
    });
});

urlModal.on('creat', function (data, cb) {
    $('body').loadingEX();
    __DBObject__.Url.creat(data, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Creat URL : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
            content.reSetUrl();
        };
    });
});

urlModal.on('updata', function (id, data, cb) {
    $('body').loadingEX();
    __DBObject__.Url.updata(id, data, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">UpData URL : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
            content.reSetUrl();
        };
    });
});

urlModal.on('delete', function (id, cb) {
    $('body').loadingEX();
    __DBObject__.Url.delete(id, function (error, docs) {
        $('body').loadingEX();
        if (error) {
            dialogEX({
                title: '警告',
                body: '<div style="padding:20px;">Delete URL : ' + error + '</div>',
                buttons: [{
                    text: '确定',
                    event: (event) => {
                        event.close();
                    },
                }],
                width: 400,
                height: 200,
            });
        } else {
            cb(docs);
            content.reSetUrl();
        };
    });
});

// menu.buttons.note.event.show();